<?php
	function nms_time_from($id){
		/*
		 * Last day*/
		if($id==1){
			$date_time_from = date('Y-m-d H:i', strtotime('-1 days'));
		}
		/*
		 * Last 2 day*/
		elseif ($id==2){
			$date_time_from = date('Y-m-d H:i', strtotime('-2 days'));
		}
		/*
		 *Last 3 day */
		 elseif ($id==3){
		 	$date_time_from = date('Y-m-d H:i', strtotime('-3 days'));
		}
		/*
		 * Last 4 day*/
		elseif ($id==4){
			$date_time_from = date('Y-m-d H:i', strtotime('-4 days'));
		}
		/*
		 * Last 1 weeks*/
		elseif($id==5){
			$date_time_from = date('Y-m-d H:i', strtotime('-7 days'));
		}
		/*
		 * Last 2 weeks*/
		elseif($id==6){
			$date_time_from = date('Y-m-d H:i', strtotime('-14 days'));
		}
		/*
		 * Last month*/
		elseif($id==7){
			$date_time_from = date('Y-m-d H:i', strtotime('-1 months'));
		}
		/*
		 *Last 2 month */
		elseif($id==8){
		 $date_time_from = date('Y-m-d H:i', strtotime('-2 months'));
		}
		/*
		 *Last 4 month */
		elseif($id==9){
			$date_time_from = date('Y-m-d H:i', strtotime('-4 months'));
		}
		/*
		 *Last 1 years */
		elseif($id==10){
			$date_time_from = date('Y-m-d H:i', strtotime('-1 years'));
		}
		/*
		 * Last 2 years*/
		elseif($id==11){
			$date_time_from = date('Y-m-d H:i', strtotime('-2 years'));
		}
		/*
		 * This day */
		 elseif ($id==12){
		 	$date_time_from = date('Y-m-d 00:00');
		}
		/*
		 * This week*/
		elseif ($id==13){
			$current_day = date("N");
			$days_to_sunday = 7 - $current_day;
			$days_from_monday = $current_day - 1;
			$date_time_from = date("Y-m-d 0:00", strtotime("- {$days_from_monday} Days"));
		}
		/*
		 * This month*/
		elseif ($id==14){
			$date_time_from = date('Y-m-01 00:00');
		}
		/*
		 *This year */
		 elseif($id==15){
		 	$date_time_from = date('Y-01-01 00:00');
		}
		/*Previous day*/
		elseif($id==16){
			$date_time_from = date('Y-m-d 00:00', strtotime('-1 days'));
		}
		/*Previous Week*/
		elseif($id==17){
			$current_day = date("N");
			$days_from_monday = $current_day - 1;
			$days_from_lastMonday = $days_from_monday + 7;
			$date_time_from = date("Y-m-d 00:00", strtotime("- {$days_from_lastMonday} Days"));
		}
		/*Previous Month*/
		elseif($id==18){
			$current_month = date("m");
			$previous_month = $current_month - 1;
			$date_time_from = date('Y-m-01 00:00',mktime(0,0,0,$previous_month,1,date("Y")));
		}
		/*Previous Year*/
		elseif($id==19){
			$date_time_from = date('Y-01-01 00:00', strtotime('-1 years'));
		}
		return $date_time_from;
	}
	function nms_time_to($id){
		/*
		 * Last day*/
		if($id==1){
			$date_time_to = date('Y-m-d H:i');
		}
		/*
		 * Last 2 day*/
		elseif ($id==2){
			$date_time_to = date('Y-m-d H:i');
		}
		/*
		 *Last 3 day */
		elseif ($id==3){
			$date_time_to = date('Y-m-d H:i');
		}
		/*
		 * Last 4 day*/
		elseif ($id==4){
			$date_time_to = date('Y-m-d H:i');
		}
		/*
		 * Last 1 weeks*/
		elseif($id==5){
			$date_time_to = date('Y-m-d H:i');
		}
		/*
		 * Last 2 weeks*/
		elseif($id==6){
			$date_time_to = date('Y-m-d H:i');
		}
		/*
		 * Last month*/
		elseif($id==7){
			$date_time_to = date('Y-m-d H:i');
		}
		/*
		 *Last 2 month */
		elseif($id==8){
			$date_time_to = date('Y-m-d H:i');
		}
		/*
		 *Last 4 month */
		elseif($id==9){
			$date_time_to = date('Y-m-d H:i');
		}
		/*
		 *Last 1 years */
		elseif($id==10){
			$date_time_to = date('Y-m-d H:i');
		}
		/*
		 * Last 2 years*/
		elseif($id==11){
			$date_time_to = date('Y-m-d H:i');
		}
		/*
		 * This day*/
		if ($id==12){
			$date_time_to = date('Y-m-d 23:59');
		}
		/*
		 * This week*/
		elseif ($id==13){
			$current_day = date("N");
			$days_to_sunday = 7 - $current_day;
			$days_from_monday = $current_day - 1;
			$date_time_to = date("Y-m-d 23:59", strtotime("+ {$days_to_sunday} Days"));
		}
		/*
		 * This month*/
		elseif ($id==14){
			$day = date("t");
	 		$date_time_to = date('Y-m-'.$day.' 23:59');
		}
		/*
		 * This year */
		elseif($id==15){
			$date_time_to = date('Y-12-31 23:59');
		}
		/*Previous day
		 * */
		elseif($id==16){
			$date_time_to = date('Y-m-d 23:59', strtotime('-1 days'));
		}
		/*Previous Week*/
		elseif($id==17){
			$current_day = date("N");
			$days_from_monday = $current_day - 1;
			$days_to_lastSunday = $days_from_monday + 1;
			$date_time_to = date("Y-m-d 23:59", strtotime("- {$days_to_lastSunday} Days"));
		}
		/*Previous Month*/
		elseif($id==18){
			$current_month = date("m");
			$previous_month = $current_month - 1;
			$date_time_to = date('Y-m-t 23:59',mktime(0,0,0,$previous_month,1,date("Y")));
		}
		/*Previous Year*/
		elseif($id==19){
			$date_time_to = date('Y-12-31 23:59', strtotime('-1 years'));
		}else{
			$date_time_to = date('Y-m-d H:i:s');
		}
		return $date_time_to;
	}
	function draw_time_filter(){
		echo "<option value='1'"; echo "/>Last Day</option>\n";
		echo "<option value='2'"; echo "/>Last 2 Days</option>\n";
		echo "<option value='3'"; echo "/>Last 3 Days</option>\n";
		echo "<option value='4'"; echo "/>Last 4 Days</option>\n";
		echo "<option value='5'"; echo "/>Last Week</option>\n";
		echo "<option value='6'"; echo "/>Last 2 Weeks</option>\n";
		echo "<option value='7'"; echo "/>Last Month</option>\n";
		echo "<option value='8'"; echo "/>Last 2 Months</option>\n";
		echo "<option value='9'"; echo "/>Last 4 Months</option>\n";
		echo "<option value='10'"; echo "/>Last Year</option>\n";
		echo "<option value='11'"; echo "/>Last 2 Years</option>\n";
		echo "<option value='12'"; echo "/>This Day</option>\n";
		echo "<option value='13'"; echo "/>This Week</option>\n";
		echo "<option value='14'"; echo "/>This Month</option>\n";
		echo "<option value='15'"; echo "/>This Year</option>\n";
		echo "<option value='16'"; echo "/>Previous Day</option>\n";
		echo "<option value='17'"; echo "/>Previous Week</option>\n";
		echo "<option value='18'"; echo "/>Previous Month</option>\n";
		echo "<option value='19'"; echo "/>Previous Year</option>\n";
	}
?>